package com.a.lib_ui.fragment;

import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import com.bumptech.glide.Glide;
import com.a.lib_ui.R;

public class BigPictureFragment extends Fragment {
    private ImageView img_picture;

    private Context context;

    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.core_ui_fragment_big_image, null);
        context = getContext();
        img_picture = view.findViewById(R.id.img_big_picture);
        img_picture.setOnClickListener(v -> requireActivity().finish());
        initData();
        return view;
    }

    public static BigPictureFragment newInstance(String url) {
        BigPictureFragment fragment = new BigPictureFragment();
        Bundle args = new Bundle();
        args.putString("url", url);
        fragment.setArguments(args);
        return fragment;
    }

    public void initData() {
        String url = (String) getArguments().get("url");
        Glide.with(context)
                .load(url)
                //.fallback(R.drawable.no_picture2)
                .error(R.drawable.no_picture)
                .into(img_picture);

    }

}
